package com.zzy.chapter3.deprecated.state;


import com.zzy.chapter3.deprecated.observe.DeprecatedAbstractObserve;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class DeprecatedAbstractOrderState {

    public final String ORDER_WAIT_PAY = "ORDER_WAIT_PAY";
    public final String ORDER_WAIT_SEND = "ORDER_WAIT_SEND";
    public final String ORDER_WAIT_RECEIVE = "ORDER_WAIT_RECEIVE";
    public final String ORDER_FINISH = "ORDER_FINISH";

    // 观察者列表
    private final static List<DeprecatedAbstractObserve> observeList = new ArrayList<>();

    // 添加观察者
    public static void addObserve(DeprecatedAbstractObserve observe) {
        observeList.add(observe);
    }

    // 移除观察者
    public static void removeObserve(DeprecatedAbstractObserve observe) {
        observeList.remove(observe);
    }

    // 通知观察者
    public static void notifyObserve(String orderId, String orderState) {
        observeList.forEach(observe -> observe.orderStateHandle(orderId, orderState));
    }

    /**
     * 创建订单
     * @param orderId
     * @param productId
     * @return
     */
    protected DeprecatedOrder createOrder(String orderId, String productId) {
        throw new UnsupportedOperationException();
    }

    /**
     * 支付订单
     * @param orderId
     * @return
     */
    protected DeprecatedOrder payOrder(String orderId) {
        throw new UnsupportedOperationException();
    }

    /**
     * 发货
     * @param orderId
     * @return
     */
    protected DeprecatedOrder sendOrder(String orderId) {
        throw new UnsupportedOperationException();
    }

    /**
     * 收货
     * @param orderId
     * @return
     */
    protected DeprecatedOrder receiveOrder(String orderId) {
        throw new UnsupportedOperationException();
    }
}
